<?php 
 include_once dirname(__FILE__)."/config.php";
 class phase_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_code_phase;
		 protected $_lib_phase;
		 protected $_code_unite;
		 protected $_code_etat;
		 protected $_date;
		 protected $_observation;
		 public function get_name_table(){ return "phase";}
		 public function get_name_code_phase(){ return "code_phase";}
		 public function get_name_lib_phase(){ return "lib_phase";}
		 public function get_name_code_unite(){ return "code_unite";}
		 public function get_name_code_etat(){ return "code_etat";}
		 public function get_name_date(){ return "date";}
		 public function get_name_observation(){ return "observation";}
		 public function set_code_phase($parametre){  $this->_code_phase=$parametre;}	
		 public function set_lib_phase($parametre){  $this->_lib_phase=$parametre;}	
		 public function set_code_unite($parametre){  $this->_code_unite=$parametre;}	
		 public function set_code_etat($parametre){  $this->_code_etat=$parametre;}	
		 public function set_date($parametre){  $this->_date=$parametre;}	
		 public function set_observation($parametre){  $this->_observation=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_code_phase(){ return $this->_code_phase;}
		 public function get_lib_phase(){ return $this->_lib_phase;}
		 public function get_code_unite(){ return $this->_code_unite;}
		 public function get_code_etat(){ return $this->_code_etat;}
		 public function get_date(){ return $this->_date;}
		 public function get_observation(){ return $this->_observation;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 phase(
			lib_phase,
			code_unite,
			code_etat,
			date,
			observation)
 VALUES(
			'".$this->_lib_phase."',
			'".$this->_code_unite."',
			'".$this->_code_etat."',
			'".$this->_date."',
			'".$this->_observation."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_lib_phase)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
lib_phase='".$this->_lib_phase."'";
}
if(!empty($this->_code_unite)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_unite='".$this->_code_unite."'";
}
if(!empty($this->_code_etat)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_etat='".$this->_code_etat."'";
}
if(!empty($this->_date)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
date='".$this->_date."'";
}
if(!empty($this->_observation)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
observation='".$this->_observation."'";
}
$sql="UPDATE 
phase SET 
 ".$sql."
								WHERE code_phase ='".$this->_code_phase."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
phase 
 
									WHERE code_phase ='".$this->_code_phase."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
phase ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		code_phase,
		lib_phase,
		code_unite,
		code_etat,
		date,
		observation
 FROM 
 phase";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_code_phase=$row->code_phase;
		$this->_lib_phase=$row->lib_phase;
		$this->_code_unite=$row->code_unite;
		$this->_code_etat=$row->code_etat;
		$this->_date=$row->date;
		$this->_observation=$row->observation;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>